  /* jshint esversion: 6 */
  $(document).ready(function() {
      ifLoged();
      var sec = location.href.split('?')[1];
      var c = decodeURIComponent(sec),
          d = JSON.parse(c), //得到原json数据
          pricenum,
          startTime = d.startTime,
          endTime = d.endTime,
          duringDay, timeStamp = startTime + ',' + endTime;
      console.log(d);

      $('.fromDay').html(d.startDay);
      $('.toDay').html(d.endDay);
      $('.leftRoomNum').html(d.room.count);
      $('#minus').on('click', function() {
          var $num = $('#roomNum'),
              num = $num.val();
          if (num > 1) {
              $num.val(--num);
              pricenum = parseInt($('#roomNum').val()) * d.room.price * d.duringDay;
              $('.totalPrice').html(pricenum);
          }
      });
      $('#plus').on('click', function() {
          var $num = $('#roomNum'),
              num = $num.val();
          if (num < d.room.count) {
              $num.val(++num);
              pricenum = parseInt($('#roomNum').val()) * d.room.price * d.duringDay;
              $('.totalPrice').html(pricenum);
          }
      });
      laydate.render({
          elem: '#fromTime', //指定元素
          format: 'yyyy年MM月dd日',
          min: 0, //今天起
          max: 30, //30天后
          value: d.startDate,
          done: function(value, date) {
              var str = date.year + '/' + date.month + '/' + date.date,
                  datey = new Date(str),
                  now = new Date(),
                  nowTimeStamp,
                  duringTime;
              const days = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
              startTime = parseInt(datey.getTime());
              $('.fromDay').html(days[datey.getDay()]);
              nowTimeStamp = now.getTime();
              if (nowTimeStamp - startTime < 86400000) {
                  startTime += 86399000; //如果日期选择为今天 择将其调整至今天 23：59
              }
              timeStamp = startTime.toString() + ',' + endTime.toString();
          }
      });
      laydate.render({
          elem: '#toTime', //指定元素
          format: 'yyyy年MM月dd日',
          min: 0, //今天起
          max: 30, //30天后
          value: d.endDate,
          done: function(value, date) {
              var str = date.year + '/' + date.month + '/' + date.date,
                  $toTime = $('.alertInfo '),
                  datey = new Date(str),
                  duringTime;
              const days = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
              endTime = datey.getTime();
              timeStamp = startTime + ',' + endTime;
              endTime = parseInt(datey.getTime());
              $('.toDay').html(days[datey.getDay()]);
              duringTime = endTime - startTime;
              if (duringTime <= 0) {
                  $('.modal-body').html('请选择开始日期之后的日期!');
                  $('.modal').modal('show');
              } else {
                  var duringDay = Math.ceil(duringTime / 86400000);
                  $toTime.html('共' + duringDay + '晚');
                  d.duringDay = duringDay;
                  pricenum = parseInt($('#roomNum').val()) * d.room.price * d.duringDay;

                  $('.totalPrice').html(pricenum);
              }
          }
      });
      $('#roomNum').on('blur', function() {
          if ($('#roomNum').val()) {

          }
      });
      $('.hotelName').html(d.hotelName);
      $('.hotelAddress').html(d.hotelAddress);
      var str = '';
      for (let i = 0; i < d.hotelPhone.length; i++) {
          str += d.hotelPhone[i] + '<br>';
      }
      $('.contact').html(str);
      $('.roomName').html(d.room.name);
      $('.roomType').html('房型名称：' + d.room.name);
      $('.bedType').html('面积：' + d.room.bedType);
      $('.network').html('宽带：' + d.room.wayOfInternet);
      $('.breakfast').html('早餐：' + d.room.breakfast);
      pricenum = parseInt($('#roomNum').val()) * d.room.price * d.duringDay;
      $('.totalPrice').html(pricenum);
      $('.submit').on('click', function() {

          //判断输入是否完全
          if ($('#customerName').val() != '' && /^1[3|4|5|7|8]\d{9}$/.test($('#phoneNum').val())) {
              ajaxXHR('post', url + 'v1/order/create', function(data) {
                  //   var a = data.data,
                  //       b = JSON.stringify(a),
                  //       c = encodeURIComponent(b);
                  //   window.location.href = "billings.html?" + c;
                  window.location.href = "myIndent.html";
              }, {
                  token: localStorage.APISHoteltoken,
                  roomName: d.room.name,
                  hotelId: d.hotelId,
                  checkTime: timeStamp,
                  roomNumber: $('#roomNum').val(),
                  customerName: $('#customerName').val(),
                  customerPhone: $('#phoneNum').val(),
              });
          } else {

          }

      });
  });